import { showDialog } from "./ui/showDialog";

export * from "./app_config";
export * from "./request";
export * from "./third";
export * from "./tree";
export const goPage = (url: string) => {
  const route = useRoute();
  const router = useRouter();
  const { shop } = route.params;
  router.push(`/${shop}-c/${url}`);
};

export const getImgPrex = (val = "") => {
  return "";
};

export const sleepPromise = (time = 5000) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, time);
  });
};

export const setPageSeo = (
  temp: {
    seoTitle?: string;
    name?: string;
    seoDesc?: string;
    ogTitle?: string;
    ogDescription?: string;
    seoKeywords?: string;
  },
  route?: any
) => {
  useHead({
    title:
      (temp.seoTitle || temp.name || "格利普") + "-成都格利普生物科技有限公司",
    meta: [
      {
        name: "keywords",
        content: temp.seoKeywords || "格利普",
        tagPriority: "critical",
      },
      {
        name: "description",
        content: temp.seoDesc || "格利普",
        tagPriority: "critical",
      },
      // og 标签主要用来定义分享出去的时候链接展示方式
      {
        name: "og:title",
        content: temp.ogTitle || "格利普",
        tagPriority: "critical",
      },
      {
        name: "og:description",
        content: temp.ogDescription || "格利普",
        tagPriority: "critical",
      },
      {
        name: "publisher", // 用于告诉页面的发布者
        content: temp.ogDescription || "格利普",
        tagPriority: "critical",
      },
    ],
  });
};

export const playVideo = (url: string, poster?: string) => {
  showDialog({
    content: () => {
      return h("video", {
        src: `${url}`,
        type: "video/mp4",
        controls: true,
        poster,
        autoplay: false,
        muted: false,
        style: {
          // marginBottom: "-6px",
          minWidth: "50vw",
          maxHeight: "70vh",
        },
      });
    },
  });
};
export function is3nMinus1(x: number): boolean {
  return (x + 1) % 3 === 0 && (x + 1) / 3 >= 1;
}
